package com.example.demo.api;

import com.example.demo.bean.Response;
import com.example.demo.bean.bis.UserState;
import com.example.demo.service.bis.UserStateService;
import com.example.demo.utils.ConstantUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zzz
 * @Title: UserStateController
 * @ProjectName test
 * @Description: TODO()
 * @date 2018/7/20
 */
@RestController
@Api(value="请假controller",tags={"请假接口"})
public class UserStateController {

    @Autowired private UserStateService userStateService;

    @ApiOperation(value="请假申请" )
    @ApiImplicitParam(name = "userState", value = "请假实体", required = true,dataType = "UserState")
    @PostMapping(value="/appeal")
    public Response insert( UserState userState){
        return new Response(ConstantUtils.SUCCEED,ConstantUtils.STRING_SUCCEED,userStateService.insert(userState));
    }

    @ApiOperation(value="请假列表" )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", required = true,dataType = "int",paramType = "form"),
    })
    @PostMapping(value="/appeal/list")
    public Response findByDeptId(Integer id){
        List<UserState> list = userStateService.findByDeptId(id);
        return new Response(ConstantUtils.SUCCEED,ConstantUtils.STRING_SUCCEED,list.size()==ConstantUtils.SUCCEED?"":list);
    }

    @ApiOperation(value="请假审批" )
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "请假主键", required = true,dataType = "int",paramType = "form"),
        @ApiImplicitParam(name = "state", value = "是否同意（1同意 0不同意 ）", required = true,dataType = "int",paramType = "form"),
    })
    @PostMapping(value="/appeal/update")
    public Response insert(Integer id,Integer state){
        return new Response(ConstantUtils.SUCCEED,ConstantUtils.STRING_SUCCEED,userStateService.update(id,state));
    }

}
